import Vue from 'vue'

import loading from '@/components/loading'
const CreateLoading = Vue.extend(loading)
const functionality = new CreateLoading({
    el:document.createElement('div')
})

functionality.show = false

const $loading = {
    show(msg) {
        functionality.show = true
        functionality.msg = msg
        document.body.appendChild(functionality.$el)
    },
    hide() {
        functionality.show = false
    }
}

export default {
    install() {
        if(!Vue.$loading){
            Vue.$loading = $loading
        } 
        Vue.mixin({
            created() {
                this.$loading = Vue.$loading
            }
        })
    }
}